package cn.android666.mediacodecasynchronous.permission

import android.app.Activity
import android.app.AlertDialog

object UiUtil {

    private var dialog: AlertDialog? = null

    fun showOneButtonDialog(
        activity: Activity,
        message: CharSequence,
        title: CharSequence = "温馨提示",
        okButtonName: CharSequence = "确定",
        okButtonClick: (() -> Unit)? = null) {

        if (activity.isFinishing) {
            return
        }

        if (dialog?.isShowing == true) {
            dialog?.cancel()
        }

        dialog = AlertDialog.Builder(activity)
            .setTitle(title)
            .setMessage(message)
            .setPositiveButton(okButtonName) { _, _ -> okButtonClick?.invoke(); dialog = null }
            .setCancelable(false)
            .show()
    }

}